package com.net.library.net;

import com.net.library.bean.RespFileUpload;
import com.net.library.interfaces.ServerDataInterface;
import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.RequestBody;
import retrofit2.Call;

import java.io.File;

/**
 * Created by 吴昶 on 2018/9/13.
 */
public class FileUpLoad {

    public static void upload(String filepath, String sid, FileCallBack<RespFileUpload> callBack){
        File file=new File(filepath);
        RequestBody requestBody=RequestBody.create(MediaType.parse("multipart/form-data"), file);
        FileRequstBody<RespFileUpload> fileRequstBody=new FileRequstBody<RespFileUpload>(requestBody,callBack);
        MultipartBody.Part part=MultipartBody.Part.createFormData("file", "file_name",fileRequstBody);
        Call<RespFileUpload> user=RetrofitServer.getInstance().createCall(ServerDataInterface.class).postPic(sid,part);
        user.enqueue(callBack);
    }
}
